package com.zlw.netty;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @ClassName HelloServer
 * @Description 客户端发送消息，服务器端返回 hello netty
 * @Author zhaoluowei
 * @Date 2020/1/16  23:27
 * @Version 1.0
 */

public class HelloServer {

    public static void main(String[] args) throws InterruptedException {

        // 定义一对线程组  就是两个线程池
        //主线程组
        EventLoopGroup boosGroup = new NioEventLoopGroup();
        //从线程组
        EventLoopGroup workerGroup = new NioEventLoopGroup();

        try {
            //启动服务器的 类
            ServerBootstrap serverBootstrap = new ServerBootstrap();
            serverBootstrap.group(boosGroup, workerGroup)
                    .channel(NioServerSocketChannel.class)
                    .childHandler(new HelloServerInit());

            //启动server
            ChannelFuture channelFuture = serverBootstrap.bind(8848).sync();

            // 监听 关闭的channel 设置关闭
            channelFuture.channel().closeFuture().sync();
        } finally {
            boosGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }


    }

}
